const MusicHttp = require("../../utils/MusicHttp")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dif: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    console.log(options);
    var {
      url
    } = options;
    var Hot = "/top/playlist/highquallity";
    var New = "/album/newest";
    var Dj = "/personalized/djprogram"
    var arr = [Hot, New, Dj];
    if(url==arr[0]){
      var music = await MusicHttp.getHttp(url);
      console.log(music);
      var dif = []
      music.data.playlists.forEach(item=>{
        var {name,id,coverImgUrl} = item;
        dif.push({
          name,
          id,
          picUrl:coverImgUrl, 
        })
      })
      console.log(dif);
      this.setData({
        dif
      })
    }else if(url==arr[1]){
      var music = await MusicHttp.getHttp(url);
      console.log(music);
      var dif = []
      music.data.albums.forEach(item=>{
        var {name,id,blurPicUrl} = item;
        dif.push({
          name,
          id,
          picUrl:blurPicUrl, 
        })
      })
      console.log(dif);
      this.setData({
        dif
      })
    }else if(url==arr[2]){
      var music = await MusicHttp.getHttp(url);
      console.log(music);
      var dif = []
      music.data.result.forEach(item=>{
        var {name,id,picUrl} = item;
        dif.push({
          name,
          id,
          picUrl,
        })
      })
      console.log(dif);
      this.setData({
        dif
      })
    }
    // var res = arr.find(item => {
    //   return item == url;
    // })
    // console.log(res);
   
 
  },
  OnClick(e){
    var {aid} = e.currentTarget.dataset;
    console.log(aid);
    wx.navigateTo({
      url: `../more/more?id=${aid}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})